package leetcode.programmer;

import java.util.*;

// 面试题 08.09. 括号
public class GenerateParenthesis {

    List<String> res = new ArrayList<>();

    public List<String> generateParenthesis(int n) {
        dfs(0,0,n,"");
        return res;
    }

    private void dfs(int left, int right, int n, String s) {
        if (left==n&& right==n){
            res.add(s);
            return;
        }
        if (left>n){
            return;
        }
        if (right>left){
            return;
        }
        dfs(left+1,right,n,s+"(");
        dfs(left,right+1,n,s+")");

    }
}
